@isTest
private class DeleteNCDataTest {
    static testMethod void testMethod1() {
        Account acc = TestUtils.createAccount();
        insert acc;

        ExWarehouse__c ew = new ExWarehouse__c();
        ew.Account__c = acc.Id;
        insert ew;

        ExWarehouse_Detail__c ewd = new ExWarehouse_Detail__c();
        ewd.ExWarehouse__c=ew.Id;
        ewd.dr__c=true;
        insert ewd;

        

        Order__c order = new Order__c();
        order.Account__c = acc.Id;
        insert order;
        Order_Product__c op = new Order_Product__c();
        op.Order__c = order.Id;
        op.dr__c=true;
        insert op;

        Sales_Invoice__c si = new Sales_Invoice__c();
        si.Account__c = acc.id;
        insert si;
        Sales_Invoice_Detail__c sid = new Sales_Invoice_Detail__c();
        sid.Sales_Invoice__c = si.Id;
        sid.dr__c=true;
        insert sid;


        List<ExWarehouse_Detail__c> ewdetailList = [SELECT id FROM ExWarehouse_Detail__c WHERE id = :ewd.Id];
        List<ExWarehouse__c> ewList = [SELECT id FROM ExWarehouse__c WHERE id = :ew.id];
        System.assertEquals(ewdetailList.size(), 1);
        System.assertEquals(ewList.size(), 1);

        System.assertEquals(1, ((List<Order__c>)[SELECT Id FROM Order__c WHERE id = :order.Id]).size());
        System.assertEquals(1, ((List<Order_Product__c>)[SELECT Id FROM Order_Product__c WHERE id = :op.Id]).size());

        System.assertEquals(1, ((List<Sales_Invoice__c>)[SELECT Id FROM Sales_Invoice__c WHERE id = :si.Id]).size());
        System.assertEquals(1, ((List<Sales_Invoice_Detail__c>)[SELECT Id FROM Sales_Invoice_Detail__c WHERE id = :sid.Id]).size());


        Test.startTest();
        System.schedule('delete detail schedule', '0 30 0-23 1-31 1-12 ? 2017-2098', new DeleteNCDetailData());
        Test.stopTest();

        ewdetailList = [SELECT id FROM ExWarehouse_Detail__c WHERE id =: ewd.Id];
        ewList = [SELECT id FROM ExWarehouse__c WHERE id = : ew.Id];
        System.assertEquals(ewdetailList.size(), 0);
        System.assertEquals(ewList.size(), 1);
        
        System.assertEquals(1, ((List<Order__c>)[SELECT Id FROM Order__c WHERE id = :order.Id]).size());
        System.assertEquals(0, ((List<Order_Product__c>)[SELECT Id FROM Order_Product__c WHERE id = :op.Id]).size());

        System.assertEquals(1, ((List<Sales_Invoice__c>)[SELECT Id FROM Sales_Invoice__c WHERE id = :si.Id]).size());
        System.assertEquals(0, ((List<Sales_Invoice_Detail__c>)[SELECT Id FROM Sales_Invoice_Detail__c WHERE id = :sid.Id]).size());

    }
    static testMethod void testMethod2(){
        Account acc = TestUtils.createAccount();
        insert acc;

        ExWarehouse__c ew = new ExWarehouse__c();
        ew.Account__c = acc.Id;
        insert ew;

        Order__c order = new Order__c();
        order.Account__c = acc.Id;
        insert order;
        Sales_Invoice__c si = new Sales_Invoice__c();
        si.Account__c = acc.id;
        insert si;

        List<ExWarehouse__c> ewList = [SELECT id FROM ExWarehouse__c WHERE id = :ew.id];
        System.assertEquals(ewList.size(), 1);
        System.assertEquals(1, ((List<Order__c>)[SELECT Id FROM Order__c WHERE id = :order.Id]).size());
        System.assertEquals(1, ((List<Sales_Invoice__c>)[SELECT Id FROM Sales_Invoice__c WHERE id = :si.Id]).size());

        Test.startTest();
        System.schedule('delete master schedule', '0 30 0-23 1-31 1-12 ? 2017-2098', new DeleteNCMainData());
        Test.stopTest();
        ewList = [SELECT id FROM ExWarehouse__c WHERE id = : ew.Id];
        System.assertEquals(ewList.size(), 0);
        System.assertEquals(0, ((List<Order__c>)[SELECT Id FROM Order__c WHERE id = :order.Id]).size());
        System.assertEquals(0, ((List<Sales_Invoice__c>)[SELECT Id FROM Sales_Invoice__c WHERE id = :si.Id]).size());

    }
}